package middleware

import (
	"github.com/e421083458/golang_common/lib"
	"github.com/gin-gonic/gin"
	"tino_manager/public"
)

func WeAppMiddleware() func(c *gin.Context) {
	return func(c *gin.Context) {
		isMatched := false
		for _, url := range lib.GetStringSliceConf("base.http.no_jwt") {
			if c.Request.URL.Path == url {
				isMatched = true
			}
		}

		if isMatched {
			c.Next()
		} else {
			err := public.GetOpenIdByHeader(c)
			if err != nil {
				ResponseError(c, 401, err, true)
				c.Abort()
				return
			}
			c.Next()
		}

	}
}
